#!/bin/bash
#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
# 服务器上项目的路径，$1是传过来的参数
gitPath="/www/wwwroot/demo/koa2-demo"
# 你自己的仓库SSH地址
gitHttp="https://gitee.com/xpengcheng/koa2-demo.git"
branch="master"
echo "Web站点路径：$gitPath"
#判断项目路径是否存在
if [ -d "$gitPath" ]; then
	cd $gitPath
    echo "拉取最新的项目文件"
    sudo git pull origin $branch
    echo "拉取成功"
else 
	mkdir -p "$gitPath"
    echo "Directory $gitPath created successfully."
    echo "设置目录权限"
    sudo chown -R www:www $gitPath
    sudo chmod -R 755 $gitPath
    echo "初始化项目文件"
    sudo git clone $gitHttp $gitPath
    echo "初始化成功"
	cd $gitPath
fi

echo "安装依赖中......"
sudo yarn
echo "部署完成......"
